import { _decorator, Animation, CCBoolean, Component } from 'cc';
import { CallBackHandler } from '../../Basic/Model/PoolObj/CallBackHandler';
const { ccclass, property } = _decorator;

@ccclass('AniScript')
export class AniScript extends Component {
  @property(CCBoolean)
  autoRelease: boolean;
  anim: Animation;

  complateHandler: CallBackHandler;

  protected onLoad(): void {
    this.anim = this.node.getComponent(Animation);
  }

  protected onEnable(): void {
    this.anim.stop();
    this.anim.play(this.anim.clips[0].name);
  }

  setHandler(handler: CallBackHandler) {
    this.complateHandler = handler;
  }

  complate() {
    if (this.complateHandler) {
      this.complateHandler.execute();
      this.complateHandler = null;
    }
  }
}
